import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';
import '../data/controllers/complaints_controller.dart';
import '../presentation/user_complaints_page/models/complaint.dart';
import '../widgets/custom_text_form_field.dart';


class AddComplaintDialog extends StatefulWidget {
  const AddComplaintDialog({super.key});

  @override
  State<AddComplaintDialog> createState() => _AddComplaintDialogState();
}

class _AddComplaintDialogState extends State<AddComplaintDialog> {
  TextEditingController noteController = TextEditingController();


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      shadowColor: Colors.grey,
      elevation: 16,
      scrollable: true,
      backgroundColor: Theme.of(context).colorScheme.secondary,
      title: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text('يرجى اخبارنا عن مشكلتك'),
          Text(
            'اذا كانت مشكلة خاصة بمكان معين الرجاء تحديد النادي والمدرب والتوقيت',
            style: theme.textTheme.titleSmall!.copyWith(color: Colors.orange),
          ),
        ],
      ),
      content: SizedBox(
        height: MediaQuery.of(context).size.height/3,
        child: CustomTextFormField(
          controller: noteController,
          textInputAction: TextInputAction.newline,
          expand: true,
          maxLines: null,
          hintText: "ادخل شرح مفصل عن مشكلتك هنا",
          title: 'الشكوى',
          fillColor: Theme.of(context).colorScheme.secondary,
          textInputType: TextInputType.multiline,
        ),
      ),
      actions: [
        TextButton(
          onPressed: () {
            if(noteController.text.isNotEmpty) {
              Complaint complaint = Complaint(
                complaint: noteController.text,
              );
              addNote(complaint);
              Navigator.pop(context);
              Navigator.pop(context);
            }
          },
          child:  Text('إضافة',style :theme.textTheme.titleMedium),
        ),
        TextButton(
          onPressed: () {
            Navigator.of(context).pop(); // إغلاق الديالوج
          },
          child:  Text('رجوع',style :theme.textTheme.titleMedium),
        ),
      ],
    );
  }

  void addNote(Complaint complaint){
    ComplaintsController.addComplaints(complaint).then((value){

    }).catchError((e){

    });
  }
}

